<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%pageContext.setAttribute("contextPath", request.getContextPath());%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>

</head>
<script type="text/javascript" src="${contextPath}/static/js/jquery-3.4.1.js"></script>
<body>
<form action="${contextPath }/testRequestBody" method="post">
    <input name="username" value="tomcat" />
    <input name="password" value="123456"/>
    <input type="submit" />
</form>
<br/>
<form action="${contextPath }/testRequestBody" method="post" enctype="multipart/form-data">
    <input name="username" value="tomcat" />
    <input name="password" value="123456"/>
    <input type="file" name="file" />
    <input type="submit" />
</form>
<form action="${contextPath }/testHttpEntity" method="post" enctype="multipart/form-data">
    <input name="username" value="tomcat" />
    <input name="password" value="123456"/>
    <input type="file" name="file" />
    <input type="submit" />
</form>
<h2><a href="${contextPath }/employee">ajax发送json数据</a></h2>
<h2><a href="${contextPath}/testResponseEntity">testResponseEntity</a></h2>
<h2><a href="${contextPath}/download">下载文件</a></h2>
</body>
<script type="text/javascript">
    $("a:first").click(function() {
        //点击发送ajax请求，请求带的数据是json
        var emp = {
            lastName : "张三",
            email : "aaa@aa.com",
            gender : 0
        };
        //alert(typeof emp);
        //js对象
        var empStr = JSON.stringify(emp);
        //alert(typeof empStr);
        $.ajax({
            url : '${contextPath}/employee',
            type : "POST",
            data : empStr,
            contentType : "application/json",
            success : function(data) {
                alert(data);
            }
        });
        return false;
    });
</script>
</html>